<?php
class Sendmail extends CI_Controller{
	public function __construct(){
		parent::__construct();
		$this->load->library("email");
	}
	
	public function contact($str=""){
		$this->db->where("name",$str);
		$row = $this->db->get("mobile_customer")->row();
		$to =$row->email;
		$customer_name = $row->name;
//		$to = "sthnews4@gmail.com";
		  try {
			$config = Array(
					'protocol' => 'smtp',
					'smtp_host' => 'ssl://smtp.googlemail.com',
					'smtp_port' => 465,
					'smtp_user' => 'eshinetv@gmail.com',
					'smtp_pass' => '#hotelsolution%',
					'mailtype'  => 'html',
					'charset' => 'utf-8',
					'wordwrap' => TRUE
		
			);
			
			$detail = 'Contact '.$customer_name.'
			Name : '.$this->input->post('name').'
			Email : '.$this->input->post('email').'
			Message : '.$this->input->post('detail');
			$this->load->library('email', $config);
			$this->email->set_newline("\r\n");
			$this->email->from($this->input->post('email'),"Contact");
		
			$this->email->to($to);
			$this->email->subject("Contact");
			$this->email->message($detail);
			$this->email->send();
			$this->email->print_debugger();
		
			$arr['StatusID']  = "1";
			$arr['Error']		="";
		}catch (Exception $e) {
			$arr['StatusID']  = "0";
			$arr['Error']		="Send Email Fail";
		}
		echo json_encode($arr);
	}
	
	public function register(){
		try {
			$config = Array(
					'protocol' => 'smtp',
					'smtp_host' => 'ssl://smtp.googlemail.com',
					'smtp_port' => 465,
					'smtp_user' => 'eshinetv@gmail.com',
					'smtp_pass' => '#hotelsolution%',
					'mailtype'  => 'html',
					'charset' => 'utf-8',
					'wordwrap' => TRUE
			);
				
			$detail = '
			<p><strong>Register EshineTV</strong></p>
			<p>Name<br/>
			&nbsp;&nbsp;&nbsp;&nbsp;-'.$this->input->post('name').'</p>
			<p>Product<br/>
			&nbsp;&nbsp;&nbsp;&nbsp;-'.$this->input->post('cat').'</p>
			<p>Email<br/>
			&nbsp;&nbsp;&nbsp;&nbsp;-'.$this->input->post('email').'</p>\
			<p>Message<br/>
			&nbsp;&nbsp;&nbsp;&nbsp;-'.$this->input->post('detail').'</p>';
			$this->load->library('email', $config);
			$this->email->set_newline("\r\n");
			$this->email->from($this->input->post('email'),"Register EshineTV");
	
			$this->email->to("sthnews4@gmail.com");
			$this->email->subject("Contact EshineTV");
			$this->email->message($detail);
			$this->email->send();
			$this->email->print_debugger();
	
			$arr['StatusID']  = "1";
			$arr['Error']		="";
		}catch (Exception $e) {
			$arr['StatusID']  = "0";
			$arr['Error']		="Send Email Fail";
		}
		echo json_encode($arr);
	}
	
	public function order($str=""){
		//get customer id
			$this->db->select("pkid,name,email");
			$this->db->where("name",$str);
			$row 			= $this->db->get("mobile_customer")->row();
			$email_to		= $row->email;
			
		try {
			$config = Array(
					'protocol' => 'smtp',
					'smtp_host' => 'ssl://smtp.googlemail.com',
					'smtp_port' => 465,
					'smtp_user' => 'eshinetv@gmail.com',
					'smtp_pass' => '#hotelsolution%',
					'mailtype'  => 'html',
					'charset' => 'utf-8',
					'wordwrap' => TRUE
			);
	
			$detail = 'Order '.$this->input->post('cat').'
			Name: '.$this->input->post('name').'
			Product: '.$this->input->post('cat').'
			Phone: '.$this->input->post('tel').'
			Email: '.$this->input->post('email').'
			Message: '.$this->input->post('detail');
			$this->load->library('email', $config);
			$this->email->set_newline("\r\n");
			$this->email->from($this->input->post('email'));
	
			$this->email->to($email_to);
			$this->email->subject("Order ".$this->input->post('cat'));
			$this->email->message($detail);
			$this->email->send();
			$this->email->print_debugger();
	
			$arr['StatusID']  = "1";
			$arr['Error']		="";
		}catch (Exception $e) {
			$arr['StatusID']  = "0";
			$arr['Error']		="Send Email Fail";
		}
		echo json_encode($arr);
	}
	
	public function gift($str=""){
		//get customer id
		$this->db->select("pkid,name,email");
		$this->db->where("name",$str);
		$row 			= $this->db->get("mobile_customer")->row();
		$email_to		= $row->email;
			
		try {
			$config = Array(
					'protocol' => 'smtp',
					'smtp_host' => 'ssl://smtp.googlemail.com',
					'smtp_port' => 465,
					'smtp_user' => 'eshinetv@gmail.com',
					'smtp_pass' => '#hotelsolution%',
					'mailtype'  => 'html',
					'charset' => 'utf-8',
					'wordwrap' => TRUE
			);
	
			$detail = 'Gift 
			Name: '.$this->input->post('name').'
			Phone: '.$this->input->post('tel').'
			Email: '.$this->input->post('email').'
			ID/PC: '.$this->input->post('detail');
			$this->load->library('email', $config);
			$this->email->set_newline("\r\n");
			$this->email->from($this->input->post('email'));
	
			$this->email->to($email_to);
			$this->email->subject("Gift  ID/PC".$this->input->post('detail'));
			$this->email->message($detail);
			$this->email->send();
			$this->email->print_debugger();
	
			$arr['StatusID']  = "1";
			$arr['Error']		="";
		}catch (Exception $e) {
			$arr['StatusID']  = "0";
			$arr['Error']		="Send Email Fail";
		}
		echo json_encode($arr);
	}
}
?>